home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1RVQ6NP (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  4.4 KB  |  103 lines

  1. package com.sun.java.swing.plaf.metal;
  2.  
  3. import com.sun.java.swing.AbstractButton;
  4. import com.sun.java.swing.ButtonModel;
  5. import com.sun.java.swing.Icon;
  6. import com.sun.java.swing.JComponent;
  7. import com.sun.java.swing.SwingUtilities;
  8. import com.sun.java.swing.UIManager;
  9. import com.sun.java.swing.plaf.ComponentUI;
  10. import com.sun.java.swing.plaf.basic.BasicGraphicsUtils;
  11. import com.sun.java.swing.plaf.basic.BasicRadioButtonUI;
  12. import com.sun.java.swing.plaf.basic.BasicToggleButtonUI;
  13. import java.awt.Component;
  14. import java.awt.Dimension;
  15. import java.awt.Font;
  16. import java.awt.FontMetrics;
  17. import java.awt.Graphics;
  18. import java.awt.Rectangle;
  19.  
  20. public class MetalRadioButtonUI extends BasicRadioButtonUI {
  21.    private static final MetalRadioButtonUI metalRadioButtonUI = new MetalRadioButtonUI();
  22.    protected ButtonModel model;
  23.    // $FF: renamed from: f java.awt.Font
  24.    Font field_0;
  25.    // $FF: renamed from: fm java.awt.FontMetrics
  26.    FontMetrics field_1;
  27.    Rectangle viewRect;
  28.    Rectangle iconRect;
  29.    Rectangle textRect;
  30.    Icon altIcon;
  31.    Icon selectedIcon;
  32.    Icon disabledIcon;
  33.  
  34.    public static ComponentUI createUI(JComponent c) {
  35.       return metalRadioButtonUI;
  36.    }
  37.  
  38.    public synchronized void paint(Graphics g, JComponent c) {
  39.       AbstractButton b = (AbstractButton)c;
  40.       this.model = b.getModel();
  41.       Dimension size = ((Component)c).getSize();
  42.       int var10000 = size.width;
  43.       var10000 = size.height;
  44.       this.field_0 = ((Component)c).getFont();
  45.       g.setFont(this.field_0);
  46.       this.field_1 = g.getFontMetrics();
  47.       this.viewRect = new Rectangle(size);
  48.       this.iconRect = new Rectangle();
  49.       this.textRect = new Rectangle();
  50.       this.altIcon = b.getIcon();
  51.       this.selectedIcon = null;
  52.       this.disabledIcon = null;
  53.       String text = SwingUtilities.layoutCompoundLabel(this.field_1, b.getText(), this.altIcon != null ? this.altIcon : super.icon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), this.viewRect, this.iconRect, this.textRect, ((BasicToggleButtonUI)this).getDefaultTextIconGap(b));
  54.       if (c.isOpaque()) {
  55.          g.setColor(((Component)b).getBackground());
  56.          g.fillRect(0, 0, size.width, size.height);
  57.       }
  58.  
  59.       if (this.altIcon != null) {
  60.          if (!this.model.isEnabled()) {
  61.             this.altIcon = b.getDisabledIcon();
  62.          } else if (this.model.isPressed() && this.model.isArmed()) {
  63.             this.altIcon = b.getPressedIcon();
  64.             if (this.altIcon == null) {
  65.                this.altIcon = b.getSelectedIcon();
  66.             }
  67.          } else if (this.model.isSelected()) {
  68.             this.altIcon = b.getSelectedIcon();
  69.          } else if (b.isRolloverEnabled() && this.model.isRollover()) {
  70.             this.altIcon = b.getRolloverIcon();
  71.          }
  72.  
  73.          if (this.altIcon == null) {
  74.             this.altIcon = b.getIcon();
  75.          }
  76.  
  77.          this.altIcon.paintIcon(c, g, this.iconRect.x, this.iconRect.y);
  78.       } else {
  79.          super.icon.paintIcon(c, g, this.iconRect.x, this.iconRect.y);
  80.       }
  81.  
  82.       if (text != null) {
  83.          if (this.model.isEnabled()) {
  84.             g.setColor(((Component)b).getForeground());
  85.             BasicGraphicsUtils.drawString(g, text, this.model.getMnemonic(), this.textRect.x, this.textRect.y + this.field_1.getAscent());
  86.          } else {
  87.             g.setColor(((Component)b).getBackground().darker());
  88.             BasicGraphicsUtils.drawString(g, text, this.model.getMnemonic(), this.textRect.x, this.textRect.y + this.field_1.getAscent());
  89.          }
  90.  
  91.          if (((JComponent)b).hasFocus() && b.isFocusPainted() && this.textRect.width > 0 && this.textRect.height > 0) {
  92.             this.paintFocus(g, this.textRect, size);
  93.          }
  94.       }
  95.  
  96.    }
  97.  
  98.    protected void paintFocus(Graphics g, Rectangle t, Dimension d) {
  99.       g.setColor(UIManager.getColor("RadioButton.focus"));
  100.       g.drawRect(t.x, t.y - 1, t.width + 1, t.height + 1);
  101.    }
  102. }
  103.